/**
 * 给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。
 * 输入: 1->1->2->3->3
    输出: 1->2->3
 */


const node = require('../../单链表/node');
const LinkedList = require('../../单链表/singlylinkedlist')
var deleteDuplicates = function (head) {
    //双指针
    let p = head.next
    let r = p.next
    while (r !== null) {
        if(p.data !== r.data) {
            p.next = r
            p = r
        }
        r = r.next
    }
    p.next = r
    return head
};

let lq = LinkedList.createByArray([1,1,2])
deleteDuplicates(lq.head)
console.log(lq.toString());